import 'package:flutter/material.dart';

class PageViewFullPage extends StatefulWidget {
  const PageViewFullPage({super.key});

  @override
  State<PageViewFullPage> createState() => _PageViewFullPageState();
}

class _PageViewFullPageState extends State<PageViewFullPage> {
  final List<Widget> _list = [];

  @override
  void initState() {
    super.initState();
    for (var i = 0; i < 10; i++) {
      _list.add(
        Center(child: Text('第${i + 1}页', style: TextStyle(fontSize: 30))),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('pageViewFull无限加载')),
      body: PageView(
        scrollDirection: Axis.vertical,
        children: _list,
        onPageChanged: (index) {
          if (index + 2 == _list.length) {
            for (var i = 0; i < 10; i++) {
              setState(() {
                _list.add(
                  Center(
                    child: Text('第${index + 1}页', style: TextStyle(fontSize: 20)),
                  ),
                );
              });
            }
          }
        },
      ),
    );
  }
}
